/**
* @file SerialThread.h in RobotConrol
* @author rebeater
* @comment
* Create on 11/6/21 3:41 PM
* @version 1.0
**/

#ifndef ROBOTCONROL__SERIALTHREAD_H_
#define ROBOTCONROL__SERIALTHREAD_H_
#include <QThread>
#include <QCoreApplication>
#include <QSerialPort>
#include <atomic>
#include "robotmessage.h"
using namespace std;
class SerialThread : public QThread {
 Q_OBJECT
 public:
  explicit SerialThread(QObject *parent = 0);
  void SetPortAndRate(QString &dev, int baud_rate);
  void run() override;
  bool Stop();
 signals:
  void dataReadyToUpdateUi(RobotMessage msg);
  void serialPortStatus(bool s);

 private:
  QString dev_;
 atomic_flag flag_stop_ ATOMIC_FLAG_INIT;
  qint32 baud_rate_{0};
  QSerialPort serial;
 private:
  bool DecodeData(uint8_t data[], int length);

};

#endif //ROBOTCONROL__SERIALTHREAD_H_
